Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@highlight-ui/button
Advanced tools
Versatile and customizable Button
and IconButton
components designed to handle user click interactions seamlessly. Enables actions to be triggered with a built-in loading feature, providing asynchronous feedback for improved user experience.
default
, emphasized
, and plain
default
, critical
, and success
default
, emphasized
and plain
Using npm:
npm install @highlight-ui/button
Using yarn:
yarn add @highlight-ui/button
Using pnpm:
pnpm install @highlight-ui/button
In your (S)CSS file:
@import url('@highlight-ui/button');
Once the package is installed, you can import the components from the library:
Button
import { Button } from '@highlight-ui/button';
Icon Button
import { IconButton } from '@highlight-ui/button';
import React from 'react';
import { Button, IconButton } from '@highlight-ui/button';
export default function ButtonExample() {
return (
<>
<Button icon="plus" variant="emphasized" tone="critical" onClick={() => console.log('Button clicked')}>
Click me!
</Button>
<IconButton icon="plus" variant="emphasized" onClick={() => console.log('Button clicked')}/>
</>
);
}
All
HTMLButtonElement
,React.PropsWithChildren
and PropsWithMetadata props are accepted with this component. In addition to these, this component has the following props
Button Props
Prop | Type | Required | Default | Description |
---|---|---|---|---|
variant | 'default' , 'emphasized' , 'plain' | No | 'default' | Determines the button's appearance (label color, background color) |
tone | 'default' , 'critical' , 'success' (Success is only available for the emphasized variant) | No | 'default' | Determines the button's tone, which is used to convey the importance or context of the action (e.g., color for success, error, etc.) |
onClick | (event: React.MouseEvent) => void | Yes | Function called when the button is clicked | |
children | React.ReactNode | Yes | The content of the button, usually a text label | |
ref | React.Ref<HTMLButtonElement> | No | Ref for the button element | |
block | boolean | No | Makes the component behave as a block element (take up the whole available space) | |
buttonState | 'default' , 'loading' , 'disabled' | No | Determines the state of the button | |
icon | string | No | The icon to be placed beside the label |
IconButton Props
Prop | Type | Required | Default | Description |
---|---|---|---|---|
icon | string | Yes | The icon to be placed beside the label | |
variant | 'default' , 'emphasized' , 'plain' | No | 'default' | Determines the button's appearance (label color, background color) |
onClick | (event: React.MouseEvent) => void | Yes | Function called when the button is clicked | |
ref | React.Ref<HTMLButtonElement> | No | Ref for the button element | |
block | boolean | No | Makes the component behave as a block element (take up the whole available space) | |
buttonState | 'default' , 'loading' , 'disabled' | No | Determines the state of the button |
The button component follows best practices for accessibility:
<button>
element to ensure proper keyboard navigation and focus handlingaria-hidden
for loading and disabled states or passing the optional aria-label
prop to the IconButtonEnter
and Space
The test below shows how the button and icon button can be tested when used within another component.
Button Test
import React, { useState } from 'react';
import { render, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Button } from '@highlight-ui/button';
function ButtonWrapper({children}) {
const handleClick = () => console.log('button clicked);
return (
<Button
onClick={handleClick}
>{children}</Button>
);
}
describe('ButtonWrapperTest', () => {
const renderButtonWrapper = () => {
return render(<ButtonWrapper />);
};
it('renders the ButtonWrapper and handles the button click', () => {
const { getByText } = renderButtonWrapper({ children: 'Click me' });
const buttonElement = getByText('Click me');
expect(buttonElement).toBeInTheDocument();
userEvent.click(buttonElement);
// Add any other expects or assertions based on your wrapper component's behavior
});
});
IconButton Test
import React, { useState } from 'react';
import { render, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { IconButton, IconButtonProps } from '@highlight-ui/button';
type IconButtonWrapperProps = Omit<IconButtonProps, 'onClick'>;
function IconButtonWrapper(props: IconButtonWrapperProps) {
const handleClick = () => console.log('button clicked');
return <IconButton onClick={handleClick} {...props} />;
}
describe('IconButtonWrapperTest', () => {
const renderIconButtonWrapper = (props) => {
return render(<IconButtonWrapper {...props} />);
};
it('renders the IconButtonWrapper and calls the onClick handler', () => {
const icon = 'plus';
const { getByRole } = renderIconButtonWrapper({ icon });
const buttonElement = getByRole('button');
expect(buttonElement).toBeInTheDocument();
userEvent.click(buttonElement);
// Add any other expects or assertions based on your wrapper component's behavior
});
});
The button component is a foundational element of the design system and can be used across various services and contexts. It provides a consistent look and feel for user interactions and actions.
Some examples of when to use the button component:
Please visit the design system documentation for usage guidelines and visual examples.
To contribute to the development of the button component, please follow the contribution guidelines. Your input and expertise are welcome and appreciated!
FAQs
The button
We found that @highlight-ui/button demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.